package com.globallogic.university;

import java.util.ArrayList;
import java.util.List;

import com.globallogic.university.documents.Curriculum;
import com.globallogic.university.events.Lecture;
import com.globallogic.university.people.Student;
import com.globallogic.university.people.StudentGroup;
import com.globallogic.university.people.Teacher;

/**
 * Class represents a university
 * 
 * @author vladyslav.bachurin
 *
 */
public class University {
	
	@Override
	public String toString() {
		return "University [allStudents=" + allStudents + ", allTeachers="
				+ allTeachers + ", allLectures=" + allLectures
				+ ", allCurriculums=" + allCurriculums + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((allCurriculums == null) ? 0 : allCurriculums.hashCode());
		result = prime * result
				+ ((allLectures == null) ? 0 : allLectures.hashCode());
		result = prime * result
				+ ((allStudents == null) ? 0 : allStudents.hashCode());
		result = prime * result
				+ ((allTeachers == null) ? 0 : allTeachers.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		University other = (University) obj;
		if (allCurriculums == null) {
			if (other.allCurriculums != null)
				return false;
		} else if (!allCurriculums.equals(other.allCurriculums))
			return false;
		if (allLectures == null) {
			if (other.allLectures != null)
				return false;
		} else if (!allLectures.equals(other.allLectures))
			return false;
		if (allStudents == null) {
			if (other.allStudents != null)
				return false;
		} else if (!allStudents.equals(other.allStudents))
			return false;
		if (allTeachers == null) {
			if (other.allTeachers != null)
				return false;
		} else if (!allTeachers.equals(other.allTeachers))
			return false;
		return true;
	}

	private List<Student> allStudents = new ArrayList<Student>();
	private List<Teacher> allTeachers = new ArrayList<Teacher>();
	private List<Lecture> allLectures = new ArrayList<Lecture>();
	private List<StudentGroup> allGroups = new ArrayList<StudentGroup>();
	private List<Curriculum> allCurriculums = new ArrayList<Curriculum>();
	private List<StudentGroup> allStudentGroups = new ArrayList<StudentGroup>();


	public Student addStudent(Student student) {
		allStudents.add(student);
		return student;
	}
	
	public Teacher addTeacher(Teacher teacher) {
		allTeachers.add(teacher);
		return teacher;
	}
	
	public Lecture addLecture(Lecture lecture) {
		allLectures.add(lecture);
		return lecture;
	}
	
	public Curriculum addCurriculum(Curriculum curriculum) {
		allCurriculums.add(curriculum);
		return curriculum;
	}
	
	public void addGroup(StudentGroup group) {
		allGroups.add(group);
	}

	public Student deleteStudent(Student student) {
		allStudents.remove(student);
		return student;
	}
	
	public Teacher deleteTeacher(Teacher teacher) {
		allTeachers.remove(teacher);
		return teacher;
	}
	
	public Lecture deleteLecture(Lecture lecture) {
		allLectures.remove(lecture);
		return lecture;
	}
	
	public Curriculum deleteCurriculum(Curriculum curriculum) {
		allCurriculums.remove(curriculum);
		return curriculum;
	}
	
	public String showEnrolledStudents(StudentGroup group) {
		String names = group.getGroupId()+":\n";
		for (Student student : group.getEnrolledStudents()) {
			names += String.format("%s %s\n", student.getLastName(), student.getFirstName());
		}
		return names;
	}

	public List<Student> getAllStudents() {
		return allStudents;
	}

	public List<Teacher> getAllTeachers() {
		return allTeachers;
	}

	public List<Lecture> getAllLectures() {
		return allLectures;
	}

	public List<Curriculum> getAllCurriculums() {
		return allCurriculums;
	}
	
	public List<StudentGroup> getAllStudentGroups() {
		return allStudentGroups;
	}

}
